Skip to content

Refactor SDP parsing to use Span<T> and StringBuilder#1655

Merged
sipsorcery merged 1 commit into
sipsorcery-org:masterfrom
paulomorgado:strings-6
Jun 1, 2026
Merged

Refactor SDP parsing to use Span<T> and StringBuilder#1655
sipsorcery merged 1 commit into
sipsorcery-org:masterfrom
paulomorgado:strings-6

Conversation

@paulomorgado

Copy link
Copy Markdown
Contributor

Replaced Regex and string.Split with Span-based parsing for SDP lines and attributes. Updated ToString methods to use StringBuilder, reducing allocations and improving performance. Standardized string comparisons and improved parsing robustness. Changes applied across SDP, media format, connection, and security description classes for better efficiency and maintainability.

Split of #1639

Replaced Regex and string.Split with Span-based parsing for SDP lines and attributes. Updated ToString methods to use StringBuilder, reducing allocations and improving performance. Standardized string comparisons and improved parsing robustness. Changes applied across SDP, media format, connection, and security description classes for better efficiency and maintainability.
@sipsorcery sipsorcery merged commit a4a563e into sipsorcery-org:master Jun 1, 2026
6 checks passed
sipsorcery added a commit that referenced this pull request Jun 1, 2026
#1658)

* Add SDP parsing regression tests for malformed crypto and rtpmap lines

Adds regression tests asserting the desired SDP parser behaviour for
recognised-but-invalid lines:

- a crypto line with a whitespace-only value -> TryParse returns false
- a crypto line missing the crypto-suite field -> TryParse returns false
- a crypto line missing key parameters       -> TryParse returns false
- an rtpmap attribute with a non-numeric payload ID is dropped (not
  round-tripped): it produces no media format entry, does not corrupt
  the valid formats, and is not re-emitted by ToString().

These encode the intended behaviour delivered by #1655. They are
expected to fail against the current master parser (which throws an
IndexOutOfRangeException on the malformed crypto lines and round-trips
the invalid rtpmap line) and to pass once #1655 lands. Tests only; no
production code changes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Potential fix for pull request finding 'Missed 'readonly' opportunity'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@paulomorgado paulomorgado deleted the strings-6 branch June 1, 2026 15:01
This was referenced Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants